package cn.com.open.itembank.logic.questiontype;

import cn.com.open.itembank.dto.QuestionImportModel;
import cn.com.open.itembank.dto.QuestionModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lucky on 2017/12/19.
 */
public class JudgementItem extends BaseChoiceItem {
    /**
     * Instantiates a new Judgement item.
     *
     * @param model the model
     */
    public JudgementItem(QuestionImportModel model) {
        super(model);
        super.mustHasChoice = false;
    }

    //region 校验答案格式

    /**
     * 校验答案格式.
     *
     * @return the boolean
     */
    @Override
    protected boolean checkAnswerFormat() {
        boolean result = true;
        if (importModel.getAnswer().size() > 1) {
            importModel.setErrorInfo("正确答案不唯一；");
            result = false;
        } else {
            List<String> tf = new ArrayList<>();
            tf.add("T");
            tf.add("F");

            if (tf.indexOf(importModel.getAnswer().get(0).trim().toUpperCase()) < 0) {
                result = false;
                importModel.setErrorInfo("答案格式不正确；");
            }
        }

        return result;
    }
    //endregion

    //region 校验答案界限

    /**
     * 校验答案界限.
     *
     * @return the boolean
     */
    @Override
    protected boolean checkAnswerLimit() {
        return true;
    }
    //endregion

    //region 获取保存模型

    /**
     * 获取保存模型.
     *
     * @return the input question model
     */
    @Override
    public QuestionModel getSaveModel() {
        QuestionModel model = super.getSaveModel();

        model.getI6().add("对");
        model.getI6().add("错");

        //answer存的是TF，i7需要01
        model.getI7().clear();
        model.getI7().add("T".equalsIgnoreCase(importModel.getAnswer().get(0)) ? "0" : "1");

        return model;
    }
    //endregion
}
